﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Office.Interop.Excel;

namespace Excel2Word
{
    public partial class FrmExcelOperation : Form
    {
        public FrmExcelOperation()
        {
            InitializeComponent();
            //获取当前工作区宽度和高度（工作区不包含状态栏）
            int ScreenWidth = Screen.PrimaryScreen.WorkingArea.Width;
            int ScreenHeight = Screen.PrimaryScreen.WorkingArea.Height;
            //计算窗体显示的坐标值，可以根据需要微调几个像素
            int x = ScreenWidth - this.Width - 5;
            int y = 200;

            this.Location = new System.Drawing.Point(x, y);

        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Hide();
            parent.UpdateDataSource();
            ExcelInputHelper.GetInstance().releaseInput(AppStore.targetWorkbook);
            parent.Show();
        }

        FrmDefineExcelSource parent;
        public void setParent(FrmDefineExcelSource parent)
        {
            this.parent = parent;
        }

        /// <summary>
        /// 设置操作提示！
        /// </summary>
        /// <param name="curTip"></param>
        public void setTip(string curTip)
        {
            this.Invoke(new MethodInvoker(() => lbTip.Text = curTip));

        }

        /// <summary>
        /// 设置操作提示！
        /// </summary>
        /// <param name="curTip"></param>
        public void SetCount(int curCount)
        {
            this.Invoke(new MethodInvoker(() => lbCount.ToString()));
        }

        /// <summary>
        /// 清空
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnReload_Click(object sender, EventArgs e)
        {
            foreach (SourceElement ele in AppStore.listEle)
            {
                ele.range1.Interior.Pattern = Constants.xlNone;
                ele.range2.Interior.Pattern = Constants.xlNone ;
            }

            AppStore.listEle.Clear();
            ExcelInputHelper.GetInstance().isKey = true;

        }

        private void btnBack_Click(object sender, EventArgs e)
        {
            if (AppStore.listEle.Count > 0)
            {
                var ele = AppStore.listEle.Last();
                if (ele.range1 != null) ele.range1.Interior.Pattern = Constants.xlNone;
                if (ele.range2 != null) ele.range2.Interior.Pattern = Constants.xlNone;
                AppStore.listEle.RemoveAt(AppStore.listEle.Count - 1);
                lbTip.Text = "回退成功！";
                ExcelInputHelper.GetInstance().isKey = true;
            }


        }

    }
}
